﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace MotaWeb.Security
{
    public interface IRoleService
    {
        void AddUsersToRoles(string[] userNames, string[] roleNames);
        string[] GetAllRoles();
        void RemoveUsersFromRoles(string[] userNames, string[] roleNames);
        bool IsUserInRole(string userName, string roleName);
        string[] GetRolesForUser(string userName);
        bool RoleExists(string roleName);
    }

    public class RoleMembershipService : IRoleService
    {
        private RoleProvider _provider;

        public RoleMembershipService()
            : this(null)
        {
        }

        public RoleMembershipService(RoleProvider provider)
        {
            _provider = provider ?? Roles.Provider;
        }

        public void AddUsersToRoles(string[] userNames, string[] roleNames)
        {
            _provider.AddUsersToRoles(userNames, roleNames);
        }

        public string[] GetAllRoles()
        {
            return _provider.GetAllRoles();
        }

        public void RemoveUsersFromRoles(string[] userNames, string[] roleNames)
        {
            _provider.RemoveUsersFromRoles(userNames, roleNames);
        }

        public bool IsUserInRole(string userName, string roleName)
        {
            return _provider.IsUserInRole(userName, roleName);
        }

        public string[] GetRolesForUser(string userName)
        {
            return _provider.GetRolesForUser(userName);
        }

        public bool RoleExists(string roleName)
        {
            return _provider.RoleExists(roleName);
        }
    }
}
